package com.besttone.http;

import com.besttone.search.Client;

public class UpdateRequest extends WebServiceHelper
{

	public static interface UpdateListener
	{
		public void onUpdateAvaiable(String msg, String url);

		public void onUpdateMust(String msg, String url);

		public void onUpdateNoNeed(String msg);

		public void onUpdateError(short code, Exception e);
	}

	private String latestVersionCode = "";
	private String url = "";
	private String versionInfo = "";
	private UpdateListener mListener = null;

	public void setListener(UpdateListener mListener)
	{
		this.mListener = mListener;
	}

	public void checkUpdate()
	{

		Client.getThreadPoolForRequest().execute(new Runnable()
		{

			@Override
			public void run()
			{
				// TODO Auto-generated method stub
				getUpdateInfo();
				Client.postRunnable(new Runnable()
				{

					@Override
					public void run()
					{
						// TODO Auto-generated method stub
						if ( !Client.getVersion(Client.getContext()) .equals( latestVersionCode ) )
						{
							mListener.onUpdateAvaiable(versionInfo, "");
						}
						else
						{
							mListener.onUpdateNoNeed("");
						}
					}
				});

			}
		});

	}

	private void getUpdateInfo()
	{
		this.latestVersionCode = "0.2.9";
		this.url = "http://droidapps.googlecode.com/files/MiniFetion-2.8.4.apk";
		this.versionInfo="更新信息：";
	}
}
